
class ThreadDemo01  implements Runnable{
    private int count=100;
    public void run() {
        while (count>0){
            try {
                Thread.sleep(100);
            }catch (Exception e){

            }
            sale();
        }
    }

    public synchronized void sale() {
        if(count>0){
            System.out.println(Thread.currentThread().getName()+",出售"+(100-count+1)+"张票");
            count--;
        }
    }
}


public class Test001 {

    public static void main(String[] args){
        ThreadDemo01 threadDemo01=new ThreadDemo01();
        Thread t1=new Thread(threadDemo01,"t1");
        Thread t2=new Thread(threadDemo01,"t2");
        t1.start();
        t2.start();
    }
}
